package com.g3.zoosite.controller;


import com.g3.zoosite.model.DwRareAnimal;
import com.g3.zoosite.service.IDwRareAnimalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * <p>
 * 珍奇动物表 前端控制器
 * </p>
 *
 * @author admin
 * @since 2021-09-28
 */
@Api(tags = "珍奇动物接口")
@Slf4j  //日志打印
@RestController
@RequestMapping("/zoosite/dwRareAnimal")
public class DwRareAnimalController {
    @Autowired
    IDwRareAnimalService dwRareAnimalService;

    //查询所有珍奇动物控制层方法
    @ApiOperation("查询全部珍奇动物信息")
    @GetMapping("/loadrareanimals")
    public List<DwRareAnimal> findRareAnimals(){
        List<DwRareAnimal> rareAnimals = dwRareAnimalService.findRareAnimals();
        return rareAnimals;
    }

    /**
     * 带数据跳转页面
     * @param id
     * @return
     */
    @ApiOperation("通过id查询珍奇动物信息")
    @GetMapping("/edit/{id}")
    public ModelAndView edit(@PathVariable Integer id){
        //TODO
        //通过id去数据库查询这条数据记录
        DwRareAnimal rareAnimal = dwRareAnimalService.findRareAnimalById(id);
        //ModelAndView 使用这个来做页面跳转
        ModelAndView mv = new ModelAndView();
        mv.setViewName("/hfy/hfy_zqdw_detail");
        mv.addObject("rareAnimal",rareAnimal);
        return mv;
    }

}
